package com.xiaoxi.exam.utils;

import cn.xinzhili.xutils.core.ErrorCode;
import cn.xinzhili.xutils.core.FailureException;
import org.hashids.Hashids;

public class HashIdsUtils {

  private static Hashids hashids = new Hashids("xzl salt", 6);

  public HashIdsUtils() {
  }

  public static String encode(long id) {
    return hashids.encode(new long[]{id});
  }

  public static long decode(String str) {
    if (str != null && !str.isEmpty()) {
      try {
        return hashids.decode(str)[0];
      } catch (Exception var2) {
        throw new FailureException(ErrorCode.INVALID_PARAMS,
            "input string " + str + " cannot be decoded");
      }
    } else {
      throw new FailureException(ErrorCode.INVALID_PARAMS, "cannot decode empty string");
    }
  }
}
